package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.MyAutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Update("update dish set status = #{status} where id = #{id}")
    void changeStatus(Integer status, Long id);

    @Select("select * from dish where id = #{id}")
    DishVO findById(Long id);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> findByCategoryId(Long categoryId);

    void deleteByIds(List<Long> ids);

    @MyAutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish values (default,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void add(Dish dish);

    void addFlavor(List<DishFlavor> flavors);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> findFlavorById(Long id);

    @Delete("delete from dish_flavor where dish_id = #{dishId}")
    void deleteFlavorByDishId(Long dishId);

    @MyAutoFill(OperationType.UPDATE)
    void update(Dish dish);
}
